<!--
 * @Author: Neko
 * @Date: 2021-04-28 17:06:51
 * @LastEditTime: 2021-06-24 16:51:08
 * @LastEditors: Neko
-->
<template>
  <contents :heightInclude="['tabBar']" class="order_preview_page">
		<u-notice-bar v-if="viewInfo.deliveryRange === 1" :volume-icon="false" :list="[$t('locales.noDelivery')]"></u-notice-bar>
    <OrderAddress edit v-model="viewInfo.userAddress" />
    <view class="box">
      <OrderGoodsInfo v-if="viewInfo.cartGoodsList" v-model="viewInfo.cartGoodsList" />
      <OrderPriceInfo v-model="viewInfo" @change="orderPriceInfoChange" />
    </view>
    <OrderButton
      v-model="viewInfo"
      :routerParams="routerParams"
      :domain-prefix="routerParams.domainPrefix"
      type="view"
    />
  </contents>
</template>

<script>
import OrderAddress from '@/components/orderAddress'
import OrderGoodsInfo from '@/components/orderGoodsInfo'
import OrderPriceInfo from '@/components/orderPriceInfo'
import OrderButton from '@/components/orderButton'
import { orderPreview } from '@/api/http/order'
export default {
  components: {
    OrderAddress,
    OrderGoodsInfo,
    OrderPriceInfo,
    OrderButton
  },
  data() {
    return {
      routerParams: {},
      viewInfo: {
        userAddress: {}
      }
    }
  },
  onLoad(opt) {
    this.routerParams = opt
  },
  onShow() {
    this.getData()
  },
  methods: {
    getData() {
      orderPreview({
        domainPrefix: this.routerParams.domainPrefix,
        sourceDomainPrefix: this.$store.getters.domainPrefix,
        // goodsIds: this.routerParams.id.split(','),
        countList: this.routerParams?.count?.split(',').filter(current => current) || [],
        isQuickBuy: this.routerParams.isQuickBuy || '',
        skuIds: this.routerParams?.skuIds?.split(',').filter(current => current) || [],
        from: this.routerParams.purchaseId || '',
        // #ifdef H5
        sourceType: 3,
        // #endif

        // #ifdef APP-PLUS
        sourceType: 1,
        // #endif
      }).then((res) => {
        if (res.code === 200) {
          this.viewInfo = res.data
        } else {
          uni.showToast({
            icon: 'none',
            title: res.message
          })
        }
      })
    },
    orderPriceInfoChange(obj) {
      this.viewInfo.remarks = obj.remarks
    }
  }
}
</script>

<style lang="scss" scoped>
.order_preview_page {
  .box {
    margin: 20rpx;
    border-radius: 12rpx;
    overflow: hidden;
    // background-color: #fff;
  }
}
</style>
